//
//  NSString+MHBase64.m
//  MH
//
//  Created by SY on 2018/11/2.
//  Copyright © 2018年 SY. All rights reserved.
//

#import "NSString+MHBase64.h"
#import "NSData+MHBase64.h"
@implementation NSString (MHBase64)
+ (NSString *)stringWithBase64EncodedString:(NSString *)string encoding:(NSStringEncoding)encoding
{
    NSData *data = [NSData dataWithBase64EncodedString:string];
    if (data)
    {
        return [[self alloc] initWithData:data encoding:encoding];
    }
    return nil;
}

+ (NSString *)stringWithBase64EncodedString:(NSString *)string
{
    return [self stringWithBase64EncodedString:string encoding:NSUTF8StringEncoding];
}

- (NSString *)base64EncodedStringWithWrapWidth:(NSUInteger)wrapWidth
{
    NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    return [data base64EncodedStringWithWrapWidth:wrapWidth];
}

- (NSString *)base64EncodedString:(NSStringEncoding)encoding
{
    NSData *data = [self dataUsingEncoding:encoding allowLossyConversion:YES];
    return [data base64EncodedString];
}

- (NSString *)base64EncodedString
{
    return [self base64EncodedString:NSUTF8StringEncoding];
}

- (NSString *)base64DecodedString:(NSStringEncoding)encoding
{
    return [NSString stringWithBase64EncodedString:self encoding:encoding];
}

- (NSString *)base64DecodedString
{
    return [NSString stringWithBase64EncodedString:self];
}

- (NSData *)base64DecodedData
{
    return [NSData dataWithBase64EncodedString:self];
}

@end
